﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace NutriLeaf.Web.Core.HealthRating
{
    public class HealthRating:IHealthRating
    {
        public void AddHealthRating(Model.HealthRating health, ref Model.NutriLeafDBEntities context)
        {
            context.HealthRatings.AddObject(health);
            context.SaveChanges();
        }

        public void RemoveHealthRating(int id, ref Model.NutriLeafDBEntities context)
        {
            context.DeleteObject(context.HealthRatings.Where(p => p.HealthRatingID == id).First());
            context.SaveChanges();
        }

        public void RemoveHealthRating(Model.HealthRating health, ref Model.NutriLeafDBEntities context)
        {
            context.DeleteObject(context.HealthRatings.Where(p => p.HealthRatingID == health.HealthRatingID).First());
            context.SaveChanges();
        }

        public Model.HealthRating GetHealthRating(int id, ref Model.NutriLeafDBEntities context)
        {
            return context.HealthRatings.Where(p => p.HealthRatingID == id).First();
        }

        public void Update(Model.HealthRating health, ref Model.NutriLeafDBEntities context)
        {
            Model.HealthRating rating = context.HealthRatings.Where(p => p.HealthRatingID == health.HealthRatingID).First();
            rating = health;
            context.SaveChanges();
        }
    }
}